package com.itheima.reggie.mapper;

import com.itheima.reggie.dto.DishDto;
import com.itheima.reggie.entity.Dish;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface DishMapper {
    //查询该类别下有没有菜品
    @Select("select count(*) from dish where category_id=#{cid} and is_deleted=0")
    Integer countByDish(Long cid);

    //添加
    @Insert("insert into dish values (null,#{name},#{categoryId},#{price},#{code},#{image}," +
            "#{description},#{status},#{sort},#{createTime},#{updateTime},#{createUser},#{updateUser},0)")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    Integer save(DishDto dishDto);

    //查询菜品和所属分类
    List<DishDto> findAll(@Param("name") String name);

    List<Dish> findAll2(@Param("name") String name);

    //根据菜品id查询一个菜品(一个菜品和多个口味)
    DishDto findById(Long id);

    //根据id修改菜品
    Integer updateById(DishDto dishDto);

    //根据id删除菜品
    @Update("update dish set is_deleted=1 where id = #{id}")
    Integer deleteById(Long id);

    //根据id改变售卖状态
    Integer updateStatusById(@Param("ids") Long[] ids,@Param("status") Integer ststus);

    //根据id改变售卖状态

    //Integer updateStatusById2(@Param("ids") Long[] ids);

    //批量删除

    Integer deleteByIds(@Param("ids") Long[] ids);

    //根据菜品分类ID,查询菜品列表
//    @Select("select * from dish where category_id = #{categoryId} and is_deleted = 0 order by sort asc")
//    List<Dish> findByCategoryId(Long categoryId);

    //根据菜品名称查询菜品
    @Select("select * from dish where name = #{name}")
    Dish findByName(String name);


    List<Dish> findByCategoryIdAndStatus(@Param("categoryId") Long categoryId,@Param("status") Integer status,@Param("name") String name);
}
